home *** CD-ROM | disk | FTP | other *** search
/ Wonky Flux Batch 2019 02 / Wonky_Flux_Batch_2019-02.zip / Wonky Flux Batch 2019-02 / 089 - Misc Stuff - PD.dsk / KEYMAC.S < prev    next >
Text File  |  2019-02-17  |  9KB  |  323 lines

  1. ********************************
  2. *                              *
  3. *           KEYMAC             *
  4. *                              *
  5. * Examples of uses of MERLIN's *
  6. * add/edit keyboard hooks at   *
  7. * $AE-$AF.                     *
  8. *                              *
  9. *   Glen E. Bredon   3/27/82   *
  10. *------------------------------*
  11. * To use: BRUN desired program *
  12. * from EXEC then invoke with   *
  13. * USER from editor.            *
  14. ********************************
  15.  
  16.           TR
  17.           EXP OFF
  18.  
  19. SAVOBJ    KBD            ;Save object?
  20. PROGNUM   KBD            ;Specify 1-5
  21.           ERR PROGNUM-1/4
  22.  
  23. INVEC     = $AE          ;Edit mode key input vector
  24. EFLG      = $F0          ;Minus when in edit mode
  25. AMPER     = $3F5
  26. STRINGS   = $860         ;Editor puts string here
  27. KEY       = $C000
  28. STROBE    = $C010
  29. BELL      = $FF3A
  30.  
  31.           DO 0
  32.  
  33. STADR     MAC
  34.           LDA #]1
  35.           STA ]2
  36.           LDA #>]1
  37.           STA ]2+1
  38.           <<<
  39.  
  40.           FIN
  41.  
  42. ********************************
  43. *
  44. * Common code to all parts:
  45.  
  46.           ORG $2F0
  47.  
  48.           LDA #$4C       ;Set up USER vector
  49.           STA AMPER
  50.           >>> STADR.START;AMPER+1
  51.           RTS            ;End of common stuff
  52.  
  53.           ERR $300-*     ;This must ORG at least $300
  54.  
  55.           PAG
  56. ********************************
  57. *
  58. *   Example 1 (Keyboard macros)
  59. *
  60. * With ESC lead in, prints a *
  61. * followed by 31 copies of chr
  62. * typed after ESC.  If this is a
  63. * space then another * is put at
  64. * the end.  The cursor is then
  65. * placed on the first character.
  66. *
  67. ********************************
  68.  
  69.           DO PROGNUM-1
  70.           ELSE
  71.  
  72. START     >>> STADR.INPUT;INVEC
  73. SETSTT    SEC
  74.           ROR STATE      ;Init STATE
  75.           RTS
  76.  
  77. INPUT     BIT STATE      ;Macro in effect?
  78.           BPL NXSTATE    ;Branch if so
  79. FRSTKEY   LDA KEY        ;Otherwise, get key
  80.           BPL FRSTKEY
  81.           BIT STROBE
  82.           CMP #$9B       ;ESC lead in?
  83.           BEQ NXK        ;Branch if so
  84.           RTS            ;Return with key if not
  85.  
  86. NXK       LDA KEY        ;Get key after leadin
  87.           BPL NXK
  88.           BIT STROBE
  89.           CMP #" "       ;Control chr?
  90.           BLT SETSTT     ;Abort if so
  91.           STA CHARAC     ;Save next chr
  92.           LDA #31        ;Init count
  93.           STA STATE
  94. AST       LDA #"*"       ;Send initial *
  95.           RTS
  96. NXSTATE   LDA CHARAC     ;Get chr
  97.           DEC STATE      ;Countdown
  98.           BNE PLUS?      ;Last count if equal
  99.           CMP #" "       ;Was chr a space?
  100.           BEQ AST        ;Substitue * for last if so
  101.           RTS
  102. PLUS?     BPL BACK       ;Branch if not done
  103.           LDA #$9F&"B"   ;Put cursor on 1st chr
  104. BACK      RTS
  105.  
  106. STATE     BRK
  107. CHARAC    BRK
  108.           DO SAVOBJ
  109.           SAVE REPEAT
  110.           FIN
  111.           FIN
  112.           PAG
  113. ***********************************
  114. *
  115. *   Example 2 (Keyboard macros)
  116. *
  117. * Keyboard macros defined for keys
  118. *   * > " ' # + X Y L S - O C A E
  119. * with the shifted ones equivalent
  120. * to their unshifted counterparts.
  121. *
  122. * Most of these are variants of
  123. * the indirect, indexed by Y
  124. * opcodes, exiting in insert mode
  125. * between the parentheses.
  126. *
  127. ***********************************
  128.  
  129.           DO PROGNUM-2
  130.           ELSE
  131.  
  132. STATE     = $60          ;Must use zero page
  133. XSAV      = $61          ;locations to keep
  134. INDEX     = $62          ;program within bounds
  135.  
  136. START     >>> STADR.INPUT;INVEC
  137.           LSR STATE      ;Init STATE
  138.           RTS
  139.  
  140. INPUT     STX XSAV       ;Must preserve X (& Y)
  141.           BIT STATE      ; if used.
  142.           BMI GETINDEX   ;Branch if doing macro
  143. FRSTKEY   JSR GETKEY     ;Otherwise, get key
  144.           CMP #$9B       ;ESC lead in?
  145.           BNE EXIT       ;Exit if not
  146. NXK       JSR GETKEY     ;Get key after lead in
  147.           CMP #"0"       ;Shift chr?
  148.           BGE NOOR
  149.           ORA #%00010000 ;Shift down
  150. NOOR      STA ENDTBL     ;In case cmd not found
  151.           AND #$7F       ; save current input
  152.           STA ENDTBL+1   ; to use for it
  153.           LDX #0
  154. CMD?      LDA MACTBL,X   ;Look for command
  155.           CMP ENDTBL     ;Match input?
  156.           BEQ GOTMAC     ;Branch if so
  157. GETCHR    INX            ;Move to next mac
  158.           LDA MACTBL,X
  159.           BMI GETCHR     ;Loop till plus
  160.           INX            ;Point to cmd byte
  161.           BNE CMD?       ;Always taken
  162. GOTMAC    INX            ;Point to macro selected
  163. SXI       STX INDEX
  164. GETINDEX  LDX INDEX      ;Get index to current chr
  165.           INC INDEX      ;Point to next chr
  166.           LDA MACTBL,X   ;Get current chr of macro.
  167.           TAX            ;In case it is WNDUP-MACTBL
  168.           CMP #WNDUP-MACTBL ;Is it windup mac?
  169.           BEQ SXI        ;Branch if so
  170.           STA STATE      ;Clear flag on last chr
  171.           ORA #$80       ;Must always set high bit
  172. EXIT      LDX XSAV
  173.           RTS
  174.  
  175. GETKEY    LDA KEY
  176.           BPL GETKEY
  177.           BIT STROBE
  178.           RTS
  179.  
  180. MACTBL
  181.           DCI ":**********"
  182.           DCI "> >>> "
  183.           ASC !2 ASC ""!
  184.           DFB $88,$1F&"I" ;Backspace & insert
  185.           ASC "7 ASC ''"
  186.           DFB $88,$1F&"I"
  187.           DCI "3 LDA #"
  188.           DCI "X LDX #"
  189.           DCI "Y LDY #"
  190.           ASC "          ; ADC"
  191.           DFB WNDUP-MACTBL
  192.           ASC "L LDA"
  193.           DFB WNDUP-MACTBL
  194.           ASC "S STA"
  195.           DFB WNDUP-MACTBL
  196.           ASC "= SBC"
  197.           DFB WNDUP-MACTBL
  198.           ASC "O ORA"
  199.           DFB WNDUP-MACTBL
  200.           ASC "C CMP"
  201.           DFB WNDUP-MACTBL
  202.           ASC "A AND"
  203.           DFB WNDUP-MACTBL
  204.           ASC "E EOR"
  205. WNDUP     ASC " (),Y"
  206.           HEX 888888     ;Backspace to between ()
  207.           DFB $1F&"I"    ;Exit in insert mode
  208.  
  209. ENDTBL    DA 0           ;Command chr put here
  210.  
  211.           ERR *-1/$3D0
  212.           DO SAVOBJ
  213.           SAVE KEYMAC
  214.           FIN
  215.           FIN
  216.           PAG
  217. *****************************************
  218. *
  219. *   Example 3 (Auto-edit)
  220. *
  221. * USER"string" establishes an auto-edit
  222. * string which will be executed on each
  223. * line of a subsequent Edit.  An Add/Insert
  224. * will disconnect the routine.
  225. *
  226. * E.g., if "string" is the sequence
  227. * control O, control J  then
  228. * control J will be inserted at the
  229. * start of each line of the edit range.
  230. *
  231. * Control R followed by > or < give the
  232. * effect during the auto edit of the
  233. * arrow keys -> and <-.
  234. *****************************************
  235.  
  236.           DO PROGNUM-3
  237.           ELSE
  238.  
  239. START     LDY #-1        ;Move string specified
  240. NXB       INY            ; in USER command
  241.           LDA STRINGS,Y
  242.           STA AUTOCMD,Y  ;(Max length = $20)
  243.           BNE NXB
  244.           STA INDEX      ;Init index to cmd
  245.           LDA INVEC+1    ;Is it connected now?
  246.           CMP #>AUTOEDIT
  247.           BEQ SETVEC     ;Skip if so
  248.           STA GETKEY+2   ;Save old invector
  249.           LDA INVEC
  250.           STA GETKEY+1
  251. SETVEC    >>> STADR.AUTOEDIT;INVEC
  252.           RTS
  253.  
  254. AUTOEDIT  BIT EFLG       ;From Add/Insert or edit?
  255.           BMI SAVY       ;Branch if from edit
  256.           LDA GETKEY+1   ;Disconnect ourselves if
  257.           STA INVEC      ; from an Add or Insert
  258.           LDA GETKEY+2
  259.           STA INVEC+1
  260. GETKEY    JMP $FD0C      ;Address changed
  261.  
  262. SAVY      STY YSAV       ;Remember Y
  263.           LDY INDEX      ;Get index to next cmd chr
  264.           INC INDEX      ;Point to next one
  265.           LDA AUTOCMD,Y  ;Get next cmd chr
  266.           BNE ISQ        ;Branch if not last one
  267.           STA INDEX      ;Init index for next line
  268.           LDA #$8D       ;Exit with CR
  269. ISQ       CMP #"Q"&$9F   ;Control Q?
  270.           BNE LEADIN
  271.           LDY #0
  272.           STY INDEX
  273. LEADIN    CMP #"R"&$9F   ;Control R lead in?
  274.           BNE DOCMD      ;Branch if not
  275.           INC INDEX      ;Bump index
  276.           LDA AUTOCMD+1,Y
  277.           CMP #"<"       ;Next chr a <
  278.           BNE RAR
  279.           LDA #"H"&$9F   ;Translate to backspace
  280. RAR       CMP #">"       ;or >
  281.           BNE DOCMD      ;Just ignore cntr R if not
  282.           LDA #"U"&$9F   ;Translate to cntr U
  283. DOCMD     LDY YSAV       ;Retrieve Y reg
  284.           RTS            ;Give editor the chr
  285.  
  286. YSAV      BRK
  287. INDEX     BRK
  288. AUTOCMD   BRK            ;Must be before $3B0
  289.           ERR *-1/$3B0
  290.           DO SAVOBJ
  291.           SAVE AUTO EDIT
  292.           FIN
  293.           FIN
  294.  
  295. ******************************************
  296. *
  297. *   Example 4 (Key redefinition)
  298. *
  299. * Translates ESC to control L (case toggle).
  300. * Remember that this works only in Edit/Add
  301. * mode and not in command mode.
  302. ******************************************
  303.  
  304.           DO PROGNUM-4
  305.           ELSE
  306.  
  307. START     >>> STADR.INPUT;INVEC
  308.           RTS
  309.  
  310. INPUT     LDA KEY
  311.           BPL INPUT
  312.           BIT STROBE
  313.           CMP #$9B       ;ESC key?
  314.           BNE BACK       ;Exit if not
  315.           LDA #"L"&$9F   ;Replace by cntr L
  316. BACK      RTS
  317.  
  318.           DO SAVOBJ
  319.           SAVE KEY REDEF
  320.           FIN
  321.           FIN
  322.           LST OFF
  323.